package com.moto.mapper;

import com.github.pagehelper.Page;
import com.moto.Vo.CarVo;
import com.moto.entity.Car;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.moto.entityDto.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 车辆表 Mapper 接口
 * </p>
 *
 * @author afei
 * @since 2023-08-28
 */
@Mapper
public interface CarMapper extends BaseMapper<Car> {


    /**
     * 新增车辆
     * @param carCatDto
     */
    @Insert("insert into car (car_name,price,gender,type,displacement,photo,mark,update_date,update_id,is_delete)" +
            "values (#{carName},#{price},#{gender},#{type},#{displacement},#{photo},#{mark},#{updateDate},#{updateId},#{isDelete })")
    void addCar(CarCatDto carCatDto);

    @Select("select max(id) from car")
    int findCarMaxId();

    @Insert("insert into cartype (car_id,cate_id) values (#{id},#{category})")
    void addCarCat(CarCatDto carCatDto);



    /**
     * 根据评分查询车辆
     */
    @Select("select car_name,price,mark,photo from car order by mark desc")
    List<CarDto> orderMarkCar();

    Page<CarVo> findAllCar(CarPageDto carPageDto);

    /**
     * 修改信息
     * @param carUpdateDto
     */
    void updateCarById(CarUpdateDto carUpdateDto);

    List<Car> userFindCar(CarSelectDto carSelectDto);


}
